@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

:: PPH系统Node.js版本检查脚本
:: 快速检查当前Node.js版本是否符合要求

echo ========================================
echo PPH Node.js Version Check
echo ========================================
echo.

:: 检查Node.js是否安装
node --version >nul 2>&1
if %errorlevel% neq 0 (
    echo ❌ Node.js not found!
    echo.
    echo Please install Node.js 18.17.1:
    echo   Download: https://nodejs.org/dist/v18.17.1/node-v18.17.1-x64.msi
    echo.
    pause
    exit /b 1
)

:: 获取当前版本
for /f "tokens=*" %%i in ('node --version') do set NODE_VERSION=%%i
echo Current Node.js version: %NODE_VERSION%
echo.

:: 检查版本是否为18.17.1
echo %NODE_VERSION% | findstr "v18\.17\.1" >nul 2>&1
if %errorlevel% neq 0 (
    echo ❌ WRONG VERSION DETECTED!
    echo.
    echo Current version: %NODE_VERSION%
    echo Required version: v18.17.1
    echo.
    echo ⚠️ FORBIDDEN VERSIONS:
    echo   - Node.js 22.x (causes sqlite3 incompatibility)
    echo   - Node.js 20.x (causes service startup failure)
    echo   - Node.js 19.x (unstable version)
    echo.
    echo ✅ SOLUTION:
    echo   1. Use nvm: nvm use 18.17.1
    echo   2. Or download: https://nodejs.org/dist/v18.17.1/node-v18.17.1-x64.msi
    echo.
    echo After fixing the version, run this script again.
    pause
    exit /b 1
) else (
    echo ✅ CORRECT VERSION!
    echo.
    echo Node.js 18.17.1 is installed and active.
    echo PPH system is ready for deployment.
    echo.
    echo Next steps:
    echo   1. Run: scripts\install-dependencies.bat
    echo   2. Run: scripts\start-services.bat
    echo.
)

pause
